package com.ithzl.capacity.controller;

import com.ithzl.capacity.pojo.EntryForm;
import com.ithzl.capacity.pojo.RESTful.RestBean;
import com.ithzl.capacity.pojo.dto.EntryFormDTO;
import com.ithzl.capacity.pojo.dto.TeamWorksDTO;
import com.ithzl.capacity.service.EntryFormService;
import jakarta.servlet.http.HttpSession;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * 报名
 */
@RestController
@RequestMapping("/signUpController")
public class SignUpController {


    @Autowired
    EntryFormService entryFormService;

    /**
     * 保存
     *
     * @param session
     * @param entryFormDTO
     * @return
     */
    @PostMapping("/save")
    public RestBean save(HttpSession session, EntryFormDTO entryFormDTO) {
        EntryForm entryForm;
        try {
            entryForm = entryFormDTO.transition();
        } catch (IOException e) {
            e.printStackTrace();
            return RestBean.abnormal();
        }
        int id=entryForm.getEntryFormId();
        // 是否有编号。有则修改，无则保存
        if (id == 0) {
            id= entryFormService.save(entryForm);
        }
        else {
            entryFormService.update(entryForm);
        }


        return RestBean.succeed(entryForm,"上传的报名表");
    }

    @PostMapping("/submit")
    public RestBean submit(@Param("entryFormId") int entryFormId){
        entryFormService.submit(entryFormId);
        return RestBean.succeed();
    }
}
